Trees
Minimally Connected Graphs
Theorem 1
Let be a connected simple graph on vertices. Then the following are equivalent.
(1) is minimally connected, that is, if we remove any edge of , then the obtained graph will not be connected.
(2) does not contain a cycle.
A connected simple graph satisfying either, and therefore, both, criteria of Theorem 1 is called a tree.
Proof
(1) (2) Let us assume that is minimally connected, but it contains a cycle . Remove the edge of . We claim that is still connected. Indeed, let and be two vertices in . As is connected, contains a path from to . If does not contain the edge , then it still connects and . If contains , then let us replace by the other (longer) arc , to get a new walk from to . As there is a walk from to in , there must also be a path. Therefore, is connected, which is a contradiction.
(2) (1) We prove that the opposite of (1) implies the opposite of (2). That will suffice, because it will imply that if (2) holds, the opposite of (1) cannot hold as that would imply the opposite of (2), therefore (1) has to hold. So "(2) implies (1)" will follow. Let us assume that is not minimally connected. That means that there is an edge in , say , so that is still connected. Then there is a path from to in . However, must then be a cycle in as it defines a path that starts in and ends in A. So contains a cycle.
Corollary
A connected graph is a tree if and only if for each pair of vertices , there is exactly one path joining and .
Theorem 2
All trees on vertices have edges. Conversely, all connected graphs on vertices with exactly edges are trees.
Proof
We use induction on . If , the statement is trivially true as a 1-vertex cycle-free graph has no edges. Let us assume that the statement is true for trees on vertices. Let be a tree on vertices. Find a leaf in (the previous lemma ensures the existence of two leaves), then delete and the only edge adjacent to it from , to get a new tree . (Note that is always a tree as it is connected and cycle-free.) This new tree has vertices, so by the induction hypothesis, it has edges. But then has edges, and the Theorem is proved.
Proposition
Let be a forest on vertices with connected components. Then has edges.
Proof
By Theorem 2, the number of vertices exceeds that of edges by one in each connected component, and the proof follows.
Cayley's Formula
For any positive integer , the number of all trees with vertex set is .
Proof
Take all trees on , and in each of them, choose two vertices, which do not have to be different, and call one of them Start, and the other one End. Do this in all possible ways for each tree. Call the objects obtained this way doubly rooted trees.
We are going to show that the number of doubly rooted trees on is by constructing a bijection from the set of all functions from to to that of doubly rooted trees on . This will prove our Theorem.
Let be a function from to . Let be the subset of elements which are part of a cycle under the action of , that is, for which there is a positive integer so that . Let . Now let , and write the integers in this order to the nodes of a tree consisting of one line of vertices. In other words, we write down the elements of in the order given by the permutation that is the product of the cycles on . Also, we mark by Start and by End.
Finally, if , but , then join the vertex to the vertex by an edge. This way we always get a tree. Indeed, we get a connected graph as the Start-End line is connected to all vertices, and we get a cycle-free graph as the only cycles created by involved vertices from , and corresponds to a single line. The tree is doubly rooted, as the vertices Start and End are marked.
To see that this is a bijection, take a doubly rooted tree on . For vertices not on the Start-End line, define to be the first neighbor of on the unique path from to the Start-End line. For the vertices on the Start-End line, define so that the image of the th smallest of them is the one that is in the th position from Start.
This shows that there is exactly one function corresponding to each doubly rooted tree, and our theorem is proved.
Minimum-weight Spanning Trees
- Create a forest (a set of trees), where each vertex in the graph is a separate tree
- Create a sorted set containing all the edges in the graph
- While is nonempty and is not yet spanning
- Remove an edge with minimum weight from
- If the removed edge connects two different trees then add it to the forest , combining two trees into a single tree
Lemma
Let and be two forests on the same vertex set , and let have less edges than . Then has an edge e that can be added to so that the obtained graph is still a forest.
Proof
Let us assume that there is no such edge . Then adding any edge of to would create a cycle in . So all edges of are between two vertices of the same component of . Therefore, has at least as many components as . This is a contradiction, however, as we know that a forest on vertices and with components has edges, so if has more edges than , it must have less components. Now we are in a position to prove the main result of this section.
Theorem
The greedy algorithm always finds the minimum-weight spanning tree.
Proof
Again, we use an indirect argument. Assume the greedy algorithm gives us the spanning tree , whereas our graph has a spanning tree whose total weight is less than that of . Let be the edges of so that holds. Similarly, let be the edges of so that holds.
Let be the step at which first "beats" . That is, let be the smallest integer so that . Such an index exists as at the end of the entire selection procedure beats , so there has to be a time takes the lead. It is also clear that as is minimal among all the edge-weights of .
As is the first index at which took the lead, the inequality must hold. Indeed, this is the only way
and
can both hold. We will deduce a contradiction from this, that is, we will prove that with holding, the greedy algorithm could not possibly choose at step . Let be the forest the greedy algorithm produced in steps, that is, the union of the edges , and let be the forest formed by the edges . Applying Lemma 10.11 to and , we see that there is an edge (for some ) that can be added to without forming a cycle. However, our definitions show that , so at step , the greedy algorithm could not add to as did not have minimum weight among the edges that could be added to without forming a cycle.
This proves by contradiction that no spanning tree can have a smaller total weight than , the tree obtained by the greedy algorithm.
Graphs and Matrices
Let be an undirected graph on labeled vertices, and define an matrix by setting equal to the number of edges between vertices and . Then is called the adjacency matrix of .
Theorem
Let be a graph on labeled vertices, let be its adjacency matrix, and let be a positive integer. Then is equal to the number of walks from to that are of length .
Proof
By induction on . For , the statement is true as a walk of length one is an edge. Now let us assume that the statement is true for , and prove it for . Let be any vertex of . If there are walks of length from to , and there are walks of length one (in other words, edges) from to , then there are walks of length from to whose next-to-last vertex is . Therefore, the number of all walks of length from to is
It follows from the induction hypothesis that the matrix defined by fulfills . It is immediate from the definition of the adjacency matrix of that .
Therefore, it follows from the definition of matrix multiplication that is in fact the -entry of , (indeed, it is the scalar product of the th row of and the th column of ), and our claim is proved.
The Number of Spanning Trees on a Graph
Let be a directed graph without loops. Let denote the vertices of , and let denote the edges of . Then the incidence matrix of is the matrix defined by
- if is the starting vertex of ,
- if is the ending vertex of , and
- otherwise.
Matrix-Tree theorem
Let #U# be a simple undirected graph. Let be the vertices of . Define the matrix by
where . Then has exactly spanning trees.
Proof
First, we turn into a directed graph by replacing each edge of by a pair of directed edges, one edge going in each direction.
Let be the incidence matrix of with the last row removed. We claim that . The entry of in position is the scalar product of the th and th row of . If , then every edge that starts or ends at contributes 1 to this inner product. Therefore, the entry of in position is the degree of in , or, in other words, twice the degree of in .
If , then every edge that starts at and ends at , and every edge that starts at and ends at contributes -1 to this inner product. Recall that is simple, so there is either no edge or one edge from to in . So the entry of in position is -2 if is an edge of , and 0 otherwise. This proves that indeed, .
This implies that . Note that each spanning tree of can be turned into different spanning trees of by orienting its edges.
Theorem
Let be a directed graph without loops, and let be the incidence matrix of . Remove any row from , and let be the remaining matrix. Then the number of spanning trees of is .
Proof
Let us assume, without loss of generality, that it was the last row of that we removed. Let be an submatrix of . (If , then cannot be connected, and it has no spanning trees.) We claim that if and only if the subgraph corresponding to the columns of is a spanning tree, and otherwise. We prove this claim by induction on . (a) Let us first assume that there is a vertex of degree one in . (The degree of a vertex in an undirected graph is the number of all edges adjacent to that vertex.) Then the th row of contains exactly one nonzero element, and that element is or . Expanding by this row, and using the induction hypothesis, the claim follows. Indeed, is a spanning tree of if and only if is a spanning tree of (b) Now let us assume that has no vertices of degree one (except possibly , the vertex associated to the deleted last row). Then is not a spanning tree. Moreover, as has edges, and is not a spanning tree, there must be a vertex in that has degree zero. If this vertex is not , then has a zero row and . If this vertex is , then each column of contains one , and one as each edge has a head and a tail. Therefore, the sum of all rows of is , so the rows of are linearly dependent, and .
So we have proved that indeed, exactly if the subgraph corresponding to the columns of is a spanning tree, and otherwise. The Binet-Cauchy formula, which can be found in most Linear Algebra textbooks, says that
where the sum ranges over all submatrices of . However, we have just seen that if and only if corresponds to a spanning tree of , and otherwise.
Corollary
The number of spanning trees of is .
Proof
The matrix associated to will have the following simple structure
To compute the determinant of this matrix, add all rows to the first, to get
Now add the first row to all other rows to get the upper triangular matrix
This shows that det as claimed.